package com.example.rabbitmq.ksdemo.consumer;

import com.example.rabbitmq.util.ConnectionUtil2;
import com.example.rabbitmq.util.ConnectionUtil3;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class Fanout3 {
    public static void main(String[] args) {
        try {
            Connection connection = ConnectionUtil3.getConnection();
            Channel channel = connection.createChannel();
//            channel.exchangeDeclare("FANOUT_EX", BuiltinExchangeType.FANOUT);
            Map<String, Object> map = new HashMap();
            map.put("x-queue-type","classic");
            channel.queueDeclare("FANOUT_QUEUE_3",true,false,false,map);
            channel.queueBind("FANOUT_QUEUE_3","FANOUT_EX","MD_XSWAP");
            channel.basicConsume("FANOUT_QUEUE_3",true,new DefaultConsumer(channel){
                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    String msg = new String(body,"UTF-8");
                    System.out.println(" [x] received : " + msg + "!"+"  envelope.getDeliveryTag()"+envelope.getDeliveryTag());
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
